package com.css.apps.base.post.action;

import java.util.List;

import com.css.apps.base.user.model.SUserPost;
import com.css.core.configuration.Environment;
import com.css.db.query.QueryCache;
import com.css.db.query.TransactionCache;
import com.css.util.Ajax;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.UserAction;

@SuppressWarnings("serial")
public class DelPostUser extends UserAction {

	private String ids;
	
	@SuppressWarnings("unchecked")
	@Override
	protected String userGo() {
		if (StringHelper.isEmpty(ids)) {
			setMessage(Messages.getString("systemMsg.fieldEmpty"));
			return ERROR;
		}
		List<String> idList = StringHelper.strToList(ids);
		List<SUserPost> upList = new QueryCache("from SUserPost where uuid in (:idList)").setParameter("idList", idList).list();
		TransactionCache tx = null;
		try {
			tx = new TransactionCache();
			tx.delete(upList);
			tx.commit();
			result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS, Messages.getString("systemMsg.success"));
			return SUCCESS;
		} catch (Exception e) {
			if (tx != null) {
				tx.rollback();
			}
			e.printStackTrace();
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			return ERROR;
		}
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

}
